package com.bayihouse.excel.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.bayihouse.common.ErrorCode;
import com.bayihouse.exception.BusinessException;

public class SexConverter implements Converter<Integer> {

    @Override
    public Class supportJavaTypeKey() {
        return Integer.class;
    }


    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }



    @Override
    public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty,
                                    GlobalConfiguration globalConfiguration) {
        String value = cellData.getStringValue();
        if (value.contains("男")) {
            return 1;
        } else if (value.contains("女")) {
            return 0;
        }
        throw new BusinessException(ErrorCode.OPERATION_ERROR, "excel中性别转换失败");
    }

}
